package cn.zxcoder.controller.SystemManage.module;

import cn.zxcoder.entity.SystemManage.Icon;
import cn.zxcoder.entity.Res;
import cn.zxcoder.service.IIconService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zx
 * @since 2023-05-06
 */
@RestController
@RequestMapping("/api/Module")
public class IconController {


    @Autowired
    IIconService iIconServiceIml;


    @GetMapping("/icon")
    public Res getIcon() {
        List<Icon> list = iIconServiceIml.list();
        return new Res(list == null, JSON.toJSONString(list), list == null ? "查找图标失败" : "查找图标成功");
    }

//    @ApiOperation("获取所有菜单名称")
//    @PostMapping("/name")
//    public Res moduleName() {
//        QueryWrapper<Icon> iconQueryWrapper = new QueryWrapper<>();
//        iconQueryWrapper.select("name");
//        List<Icon> list = iIconServiceIml.list(iconQueryWrapper);
//        List<String> list1 = new ArrayList<>();
//        for (Icon icon : list) {
//            list1.add(icon.getName());
//        }
//        return new Res(true,JSON.toJSONString(list1),"查询成功");
//    }


    @GetMapping("/url/{moduleName}")
    public Res getIconUrl(@PathVariable String moduleName) {
        QueryWrapper<Icon> iconQueryWrapper = new QueryWrapper<>();
        iconQueryWrapper.eq("name", moduleName);
        iconQueryWrapper.select("url");
        Icon one = iIconServiceIml.getOne(iconQueryWrapper);
        boolean res = one != null;
        return new Res(res, JSON.toJSONString(Objects.requireNonNull(one).getUrl()), "查找图标url成功");
    }


}
